#include "observer.h"

void ConcreteSubject::attach(Observer* obs)
{
    std::cout << obs->getName() << "订阅了该主题" << std::endl;
    m_observers.push_back(obs);
}

void ConcreteSubject::detach(Observer* obs)
{
    std::cout << obs->getName() << "取消订阅该主题" << std::endl;
    m_observers.remove(obs);
}

void ConcreteSubject::notify()
{
    for(auto obs : m_observers){
        obs->update();
    }
}

void ConcreteObserver::update()
{
    std::cout<< m_name << "收到通知，已更新" << std::endl;
}
